﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using CCF20Model;

namespace CCF20
{
    /// <summary>
    /// Interaction logic for CompanyProfile.xaml
    /// </summary>
    public partial class UpdateCompanyProfile : UserControl
    {
        CCF20Entities ccf20Ent;
        CompanyProfile profile;
        bool isNew = false;
        public UpdateCompanyProfile()
        {
            InitializeComponent();
            ccf20Ent = new CCF20Entities();
            
            profile = ccf20Ent.CompanyProfiles.FirstOrDefault();
            if (profile == null)
            {
                isNew = true;
                profile = new CompanyProfile();
            }
            this.DataContext = profile;
        }
        
        private void SaveProfile_Click(object sender, RoutedEventArgs e)
        {
            Button btn = (Button)sender;
            if (btn.Content.ToString() == "保存")
            {
                if (isNew)
                {
                    ccf20Ent.CompanyProfiles.AddObject(profile);
                }
                profile.Operator = (string)Application.Current.Properties["CurrentUser"];
                ccf20Ent.SaveChanges();
                MessageBox.Show("保存成功");
            }
            else
            {
                CCFZIC zic = new CCFZIC();
                string ret = zic.UpdateCompanyProfile(this.txtIDSUserName.TextBoxValue,
                                         this.txtCustomerName.TextBoxValue,
                                         this.txtOwnerName.TextBoxValue,
                                         this.txtFirstMobile.TextBoxValue,
                                         this.txtContactPhone.TextBoxValue,
                                         this.txtFax.TextBoxValue,
                                         this.txtWebSite.TextBoxValue,
                                         this.txtAddress.TextBoxValue);
                MessageBox.Show(ret);
            }
            
            
            
            
        }
    }
}
